<?php
/**
*	短信sms使用云片网平台
*/
namespace Rainrock\Framework\Chajian;


use Rainrock\Framework\kernel\base\Base;

class smsyunpianChajian extends smsChajian{

	private $sendurl 		= 'https://sms.yunpian.com/v2/sms/batch_send.json';
	
	private $yunpian_key 	= '你的短信apikey'; //这里填写你的云片网的apikey，可以到配置文件加上yunpian_key参数
	
	
	public function initChajian()
	{
		parent::initChajian();
		$this->yunpian_key 	 = Base::getConfig('sms_yunpian_key');
	}
	
	
	/**
	*	调用的需重写
	*/
	public function sendsms($mobile, $cont, $sign, $params)
	{

		if(!$this->yunpian_key)return $this->returnerror('未配置云片网短信key');
		
		$text = '【'.$sign.'】'.$cont.''; //发的短信

		$arr['apikey'] 	= $this->yunpian_key;
		$arr['mobile'] 	= $mobile;
		$arr['text'] 	= $text;
		$result 		= $this->c('curl')->postcurl($this->sendurl, $arr);
		
		if($this->isempt($result))return returnerror('发送失败');
		
		$barr 			= json_decode($result, true);
		$data 			= $this->arrvalue($barr,'data');
		
		$sendbo 		= false;
		$msg 			= '';
		if(is_array($data)){
			foreach($data as $k=>$rs){
				if($rs['code']==0){
					$sendbo	= true;
				}else{
					$msg 	.= $rs['msg'].';';
				}
			}
		}else{
			if($barr['msg'])$msg = $barr['msg'];
		}
		
		//成功
		if($sendbo){
			return $this->returnsuccess();
		}else{
			return $this->returnerror('发送失败:'.$msg.$text.'', 202);
		}
	}
	
	
}